/*
 * Queue.h
 *
 *  Created on: Oct 29, 2012
 *  Author: Trenton Nall
 *  Assignment: Homework 7
 */

#ifndef QUEUE_H_
#define QUEUE_H_

#include <vector>
using std::vector;

// Class Purpose: Models the behavior of a queue specified for problem 2
//		of homework 7. Method documentation is below.
template <class Type> class Queue {

public:
	Queue();
	virtual ~Queue();
	Type dequeue();
	void enqueue(const Type &item);
	void empty();
	int size();
private:
	vector<Type> storage; // for storing queue items
};


/**************************************************************
 Function enqueue
 PURPOSE: adds an item to the queue
 PARAMETERS:
 	 item - item to be added to the queue
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: Adds an item to the internal storage.
 ***************************************************************/
template <class Type> void Queue<Type>::enqueue(const Type &item) {
	// store item in internal storage
	storage.push_back(item);
}

/**************************************************************
 Function dequeue
 PURPOSE: removes an item from the queue
 PARAMETERS: none
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: Removes an item to the internal storage.
 ***************************************************************/
template <class Type> Type Queue<Type>::dequeue() {
	// throw an exception is caller attempts to
	// dequeue from an empty queue
	if (size() < 1) {
		throw -1;
	}

	// get next item in queue and then delete it from internal storage
	Type frontItem = storage.front();
	storage.erase(storage.begin(), storage.begin() + 1);

	// return first next item from queue
	return frontItem;
}

/**************************************************************
 Function empty
 PURPOSE: removes all items from the queue
 PARAMETERS: none
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: Removes all items from internal storage.
 ***************************************************************/
template <class Type> void Queue<Type>::empty() {
	// clear internal storage
	storage.clear();
}

/**************************************************************
 Function size
 PURPOSE: gets the current number of items in the queue
 PARAMETERS: none
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: none
 ***************************************************************/
template <class Type> int Queue<Type>::size() {
	// get the size of internal storage = # of item in queue
	return storage.size();
}

/**************************************************************
 Function Queue
 PURPOSE: constructs a new queue object and creates internal storage
 PARAMETERS: none
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: Creates internal storage for queue items.
 ***************************************************************/
template <class Type> Queue<Type>::Queue() : storage() {
}

/**************************************************************
 Function ~Queue
 PURPOSE: removes all items from the queue on destruction of object
 PARAMETERS: none
 CALLED BY: testQuestion2Queue
 SIDE EFFECTS: Removes all items from internal queue storage.
 ***************************************************************/
template <class Type> Queue<Type>::~Queue() {
	// clears items from internal storage
	storage.clear();
}

#endif /* QUEUE_H_ */
